package com.jishuo.nontax.web.checkbill;

import com.jishuo.base.annotation.UserAuthority;
import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.GridResult;
import com.jishuo.base.bean.Pagination;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.config.AppConfig;
import com.jishuo.base.config.NonTaxConfig;
import com.jishuo.base.service.UserService;
import com.jishuo.nontax.bean.vo.BankCheckBillVO;
import com.jishuo.nontax.bean.vo.CheckResultVO;
import com.jishuo.nontax.bean.vo.PreerrVO;
import com.jishuo.nontax.bean.vo.PreresultsVO;
import com.jishuo.nontax.bfc.service.BankCheckBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * 对账
 */
@Slf4j
@Controller
@RequestMapping(value = "/bill/bankcheckbill", name = "对账")
@UserAuthority(menu = {"web/bankcheckbill/index","sys/basedata/index","sys/bankcheckbill/index","bill/bankcheckbill"})
public class BankCheckBillController {
    @Resource
    private BankCheckBillService bankCheckBillService;
    @Resource
    private UserService userService;

    // 页面文件位置
    private String prefix = "bill/";

    @RequestMapping(value = {"bankcheckbill"}, name = "对账数据处理")
    public String index(@PathVariable(required = false) String page) {
        return prefix + "bankcheckbill";
    }

    @ResponseBody
    @RequestMapping(value = "findPrereSultsPage", name = "对账数据列表")
    public GridResult<PreresultsVO> findPrereSultsPage(PreresultsVO preresultsVO, Pagination pagination) {
        return new GridResult<>(bankCheckBillService.findPrereSultsPage(preresultsVO,pagination));
    }

    @ResponseBody
    @RequestMapping(value = "check", name = "预审")
    public BaseResult check(long bankid,String paybankdt) {
        return bankCheckBillService.check(bankid,paybankdt);
    }

    /**
     * @author hlp
     * @date 2023/3/16 09:42
     * @Description: 向财政发送对账信息
     */
    @ResponseBody
    @RequestMapping(value = "sendBankCheckBill", name = "向财政发送对账信息")
    public BaseResult sendBankCheckBill(long bankid,String paybankdt,String accountcode,String usercode,String userpwd, HttpSession session) {
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return bankCheckBillService.sendBankCheck(bankid, accountcode, paybankdt, true);
    }

    @ResponseBody
    @RequestMapping(value = "findPrereSultsExport", name = "对账处理列表导出")
    public void findPrereSultsExport(PreresultsVO preresultsVO, HttpServletResponse response) throws IOException {
        bankCheckBillService.findPrereSultsExport(preresultsVO,response);
    }

    // ----------------------------------------------------------------------------------------------对账数据处理页面完成

    @RequestMapping(value = {"bankcheckbillcz"}, name = "财政对账结果")
    public String czindex(@PathVariable(required = false) String page) {
        return prefix + "bankcheckbillcz";
    }

    @ResponseBody
    @RequestMapping(value = "findPreerrPage", name = "财政对账结果列表")
    public GridResult<PreerrVO> findPreerrPage(PreerrVO preerrVO, Pagination pagination) {
        return new GridResult<>(bankCheckBillService.findPreerrPage(preerrVO,pagination));
    }


    @RequestMapping(value = {"bankcheckbillinquiry", "bankcheckbillinquiry/{page}"}, name = "全部预审")
    public String inquiryindex(@PathVariable(required = false) String page) {
        return prefix + ((page == null) ? "inquiryindex" : page);
    }

    @RequestMapping(value = {"webpay", "webpay/{page}"}, name = "全部预审")
    public String webpay(@PathVariable(required = false) String page) {
        return prefix + ((page == null) ? "webpay" : page);
    }
    @RequestMapping(value = {"bankincheck", "bankincheck/{page}"}, name = "内部对账")
    public String bankincheck(@PathVariable(required = false) String page) {
        return prefix + ((page == null) ? "bankincheck" : page);
    }

    /**
     * @author hlp
     * @date 2023/3/16 09:23
     * @Description: 对账信息发送详情列表分页
     */
    @ResponseBody
    @RequestMapping(value = "findBankCheckBillPage", name = "对账信息发送详情列表分页")
    public GridResult<BankCheckBillVO> findBankCheckBillPage(BankCheckBillVO bankCheckBillVO, Pagination pagination) {
        return new GridResult<>(bankCheckBillService.findBankCheckBillPage(bankCheckBillVO,pagination));
    }

    @ResponseBody
    @RequestMapping(value = "selbankincheck", name = "内部对账")
    public GridResult<CheckResultVO> selbankincheck(String paybankdt, Pagination pagination){
        return new GridResult<>(bankCheckBillService.findBankCheckResult(paybankdt,pagination));
    }

   /**
    * @author hlp
    * @date 2023/3/16 11:33
    * @Description: 财政对账结果列表
    */


    /**
     * @author hlp
     * @date 2023/3/16 14:24
     * @Description: 向财政提取对账数据
     */
    @ResponseBody
    @RequestMapping(value = "getcheckdata", name = "向财政提取对账数据")
    public BaseResult getcheckdata(long bankid,String paybankdt) {
        return bankCheckBillService.getcheckdata(bankid, paybankdt);
    }


    @ResponseBody
    @RequestMapping(value = "findPreerrExport", name = "财政对账列表导出")
    public void findPreerrExport(PreerrVO preerrVO, HttpServletResponse response) throws IOException {
        bankCheckBillService.findPreerrExport(preerrVO,response);
    }

    @ResponseBody
    @RequestMapping(value = "autocheck1", name = "全部预审并发送")
    public BaseResult autocheck1(String paybankdt){
        return bankCheckBillService.autocheck1(paybankdt);
    }

    @ResponseBody
    @RequestMapping(value = "selbankcheckdetail",name = "查看对账处理详情")
    public GridResult<PreerrVO> findbankcheckdetail(PreresultsVO preresultsVO) {
        List<PreerrVO> bankCheckDetail = bankCheckBillService.findBankCheckDetail(preresultsVO);
        return new GridResult<>(bankCheckDetail);
    }

    /**
     * @author hlp
     * @date 2023/6/15 09:56
     * @Description: 网银缴费
     */
    @ResponseBody
    @RequestMapping(value = "selwebpay", name = "网银缴费列表")
    public GridResult<BankCheckBillVO> selwebpay(BankCheckBillVO bankCheckBillVO, Pagination pagination) {
        return new GridResult<>(bankCheckBillService.selwebpayPage(bankCheckBillVO,pagination));
    }

    /**
     * @author hlp
     * @date 2023/6/15 11:48
     * @Description: 网银缴费修改操作
     */
    @ResponseBody
    @RequestMapping(value = "editWebpay", name = "网银缴费修改")
    public BaseResult editWebpay(BankCheckBillVO bankCheckBillVO) {
        return bankCheckBillService.editWebpay(bankCheckBillVO);
    }

    /**
     * @author hlp
     * @date 2023/6/15 11:48
     * @Description: 删除网银缴费
     */
    @ResponseBody
    @RequestMapping(value = "deleteWebpay", name = "删除网银缴费")
    public BaseResult deleteWebpay(String bankcheckids) {
        return bankCheckBillService.deleteWebpay(bankcheckids);
    }

    /**
     * @author hlp
     * @date 2023/6/15 15:33
     * @Description: 网银缴费导出
     */
    @ResponseBody
    @RequestMapping(value = "webpayExport", name = "网银缴费导出")
    public void webpayExport(BankCheckBillVO bankCheckBillVO, HttpServletResponse response) throws IOException {
        bankCheckBillService.webpayExport(bankCheckBillVO,response);
    }

    @Resource
    NonTaxConfig nonTaxConfig;

    @RequestMapping(value = "/incheck", method = {RequestMethod.GET,RequestMethod.POST})
    public BaseResult incheck(HttpServletRequest request, HttpServletResponse response, String paybankdt) throws Exception {
        return bankCheckBillService.incheck(paybankdt);
    }

}
